#include <iostream>
using namespace std;

void swap(int *total_socre,int *chinese,int *index,int j) {
    int temp = total_socre[j];
    total_socre[j] = total_socre[j + 1];
    total_socre[j + 1] = temp;

    temp = index[j];
    index[j] = index[j + 1];
    index[j + 1] = temp;

    temp = chinese[j];
    chinese[j] = chinese[j + 1];
    chinese[j + 1] = temp;
}


int main() {
    int n;
    cin >> n;
    int total_socre[n],chinese[n],index[n];
    for(int i = 0; i < n; i++) {
        int chinese_temp,math,english;
        cin >> chinese_temp >> math >> english;
        total_socre[i] = chinese_temp + math + english;
        index[i] = i + 1;
        chinese[i] = chinese_temp;
    }

    // 按照总分进行排序,使用冒泡排序
    for (int i = 0;i < n - 1;i++) {
        for (int j = 0;j < n - i - 1;j++) {
            // 如果后一个分数大于前一个分数，进行交换
            if (total_socre[j] < total_socre[j + 1]) {
                swap(total_socre,chinese,index,j);
            }else if (total_socre[j] == total_socre[j + 1]) {
                // 如果分数相等，再比较语文成绩，如果后一个成绩大于前一个，进行交换
                if (chinese[j] < chinese[j + 1]) {
                    swap(total_socre,chinese,index,j);
                }else if (chinese[j] == chinese[j + 1]) {
                    // 如果语文成绩相同，再比较学号，如果后一个学号小于前一个，进行交换
                    if (index[j] > index[j + 1]) {
                        swap(total_socre,chinese,index,j);
                    }
                }
            }
        }
    }

    for (int i = 0;i<5;i++) {
        cout << index[i] << " " << total_socre[i] << endl;
    }
}